home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Devices & Hardware / NuBus⁄Slot Manager / Slot Tools / crcPatch folder / crcCalc.a next >
Encoding:
Text File  |  1990-09-14  |  3.7 KB  |  134 lines  |  [TEXT/MPS ]

  1.  
  2. ;=====================================================================
  3. ;
  4. ; Copyright Apple Computer, Inc. 1986
  5. ; All Rights Reserved
  6. ;
  7. ;=====================================================================
  8. ;
  9. ;    File           : CRCCalc.a
  10. ;    Author         : xxxxxx xxxxxx, July 30, 1986.
  11. ;    Description    : This file contains the CRC calculation.
  12. ;
  13. ;=====================================================================
  14.  
  15. ;=====================================================================
  16. ;    Initial Assembler Directives
  17. ;=====================================================================
  18. ;Include files
  19.                 INCLUDE    'SysEQU.a'
  20.                 INCLUDE    'ROMEqu.a'        ;Declaration ROM EQU's
  21.                 INCLUDE    'SlotEqu.a'
  22.  
  23. ;=====================================================================
  24. ; _CalcCRC : Calculate CRC
  25. ;
  26. ; PROCEDURE _CalcCRC(SizeCode,DataPtr,crc);
  27. ;=====================================================================
  28. _CalcCRC        PROC    EXPORT
  29.  
  30. ;VAR
  31. RetnAddr$a        EQU        A0
  32. DataPtr$a        EQU        A1
  33. crcAdrL$a        EQU        A2
  34. crcAdrH$a        EQU        A3
  35. Temp$a            EQU        A4
  36. TopOfData$a        EQU        A5
  37.  
  38. SizeCode$d        EQU        D0
  39. crcPos$d        EQU        D1
  40. crc$d            EQU        D2
  41. Temp$d            EQU        D3
  42. Index$d            EQU        D4
  43.  
  44. ;  Define stack-frame
  45. StackFrame        RECORD {A6Link},DECR
  46. SizeCode        DS.L    1            ;size of code
  47. DataPtr            DS.L    1            ;pointer to data
  48. crc@            DS.L    1            ;VAR crc:longint
  49. Return            DS.L    1            ;Return address
  50. A6Link            DS.L    1            ;Old A6
  51.                 ENDR
  52.  
  53. ;  Other
  54. dataPtr           EQU         $4                        ; [handle]
  55.  
  56. ;----------------------------------------------------------------------
  57. ; _CalcCRC
  58. ;----------------------------------------------------------------------
  59. ;BEGIN 
  60. ;;;;;                WITH    VDPageInfo, SlotIntQElement
  61.                     WITH    FHeaderRec, StackFrame
  62.                     
  63. ;  Allocate local vars
  64.                 LINK    A6,#0
  65.                 MOVEM.L    A2-A5/D3-D4,-(SP)                ;Save registers
  66.                 
  67.                 
  68. ;  Calculate the address of the crc value.
  69.                 MOVE.L    SizeCode(A6),TopOfData$a        ;TopOfData$a := Top of data
  70.                 ADD.L    DataPtr(A6),TopOfData$a
  71.                 
  72.                 MOVE.L    TopOfData$a,crcAdrL$a            ;crcAdrL$a := TopOfData$a - (fhBlockSize-FH_crc)  {Addr of crc MSB}
  73.                 SUB.L    #fhBlockSize-fhCRC,crcAdrL$a
  74.                 MOVE.L    crcAdrL$a,crcAdrH$a                
  75.                 ADD.L    #3,crcAdrH$a                    ;Addr of crc LSB
  76.                 
  77.                 
  78. ;  Determine the size of the declaration data to be checked.
  79.                 MOVE.L    TopOfData$a,Temp$a                ;Temp$a := TopOfData$a - (fhBlockSize-FH_Length)  {Addr of Length field}
  80.                 SUB.L    #fhBlockSize-fhLength,Temp$a    ;Index := length of crc data.
  81.                 MOVE.L    (Temp$a),Index$d                    
  82.                 SUBQ.L    #1,Index$d                        ;Adjust index for DBF
  83.  
  84.                 MOVEQ    #0,crc$d                        ;crc$d := 0
  85.                 MOVE.L    DataPtr(A6),DataPtr$a            ;DataPtr$a := pointer to data
  86.             
  87.                 MOVE.L    SizeCode(A6),Temp$d                ;Adjust DataPtr$a
  88.                 SUB.L    Index$d,Temp$d
  89.                 ADD.L    Temp$d,DataPtr$a
  90.                 SUB.L    #1,DataPtr$a
  91.                 
  92.                 
  93. ;  Calc the crc value.
  94.                 MOVEQ    #0,Temp$d                        ;Temp$d := 0
  95.  
  96.                                                         ;REPEAT
  97. Repeat            ROL.L    #1,crc$d                        ;  Rotate-left the crc value.
  98.  
  99.                 CMP.L    crcAdrL$a,DataPtr$a                ;  IF DataPtr$a IN [crcAdrL$a..crcAdrH$a] THEN
  100.                 BLT.S    C10
  101.                 CMP.L    crcAdrH$a,DataPtr$a
  102.                 BGT.S    C10
  103.  
  104.                 ADDQ.L    #1,DataPtr$a                    ;    DataPtr$a := DataPtr$a + 1 {Do not include crc in calculation}
  105.                 BRA.S    Until                            
  106.                                                         ;  ELSE
  107. C10                MOVE.B    (DataPtr$a)+,Temp$d                ;    Temp$d := DataPtr$a^; DataPtr$a := DataPtr$a + 1
  108.                 ADD.L    Temp$d,crc$d                    ;    crc$d := crc$d + Temp$d
  109.  
  110. Until            DBF        Index$d,Repeat
  111.                                                         ;UNTIL Index$d < 0
  112.  
  113.  
  114. ;  Patch in the crc result.
  115.                 MOVE.L    crc$d,(crcAdrL$a)
  116.                 
  117.  
  118. ;  Move crc result to calling routine.
  119.                 MOVE.L    crc@(A6),Temp$a
  120.                 MOVE.L    crc$d,(Temp$a)
  121.                 
  122.  
  123. ;  Restore globals, cleanup stack & return        
  124. End                MOVEM.L    (SP)+,A2-A5/D3-D4                ;Restore registers
  125.                 UNLK    A6                                ;Clear stack frame of local vars
  126.                 MOVE.L    (SP)+,RetnAddr$a                ;Remove return address
  127.                 ADD.L    #12,SP                            ;Clear stack-frame of parameters
  128.                 JMP        (RetnAddr$a)                    ;Return
  129.                 
  130.                 ENDWITH    
  131.                 
  132.                 ENDP
  133.                 
  134.                 END